package com.rundatop.wx.service.impl;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.rundatop.wx.util.WxUtil;


/**
 * 一个低端小气没档次的程序狗 JavaDog
 * blog.javadog.net
 *
 * @BelongsProject: springboot-wexin
 * @BelongsPackage: net.javadog.springbootwexin.service
 * @Author: hdx
 * @CreateTime: 2020-02-14 20:43
 * @Description: 微信相关service
 */
@Service
public class WxService {
	
	
	private static String AppId;
	
	public static String getAppId() {
		return AppId;
	}
    @Value("${wx.app-id}")
    public void setAppId(String appId) {
        AppId = appId;
    }
    private static String AppSecret;
    
    public static String getAppSecret() {
		return AppSecret;
	}
    @Value("${wx.app-secret}")
	public void setAppSecret(String appSecret) {
		AppSecret = appSecret;
	}
    
    /**
    *@Author: hdx
    *@CreateTime: 20:46 2020/2/14
    *@param:  shareUrl 分享的url
    *@Description: 初始化JSSDKConfig
    */
    public Map initJSSDKConfig(String url) throws Exception {
        //获取AccessToken
//    	url = "http://sqftic.natappfree.cc/index.html?/pages/index/map1/map1";
        String accessToken = WxUtil.getJSSDKAccessToken();
        System.out.println("accessToken:"+accessToken);
        //获取JssdkGetticket
        String jsapiTicket = WxUtil.getJssdkGetticket(accessToken);
        String timestamp = Long.toString(System.currentTimeMillis() / 1000);
        String nonceStr = StringUtils.remove(UUID.randomUUID().toString(),"-");
        String signature = WxUtil.buildJSSDKSignature(jsapiTicket,timestamp,nonceStr,url);
        Map<String,String> map = new HashMap<String,String>();
        System.out.println(jsapiTicket);
        System.out.println(nonceStr);
        System.out.println(timestamp);
        System.out.println(url);
        System.out.println(signature);
        map.put("url", url);
        map.put("jsapi_ticket", jsapiTicket);
        map.put("nonceStr", nonceStr);
        map.put("timestamp", timestamp);
        map.put("signature", signature);
        map.put("appid", AppId);
        return map;
    }
	public Map reverseGeocoder(String loc) {
		String mapUrl = WxUtil.getMapReverseGeocoderUrl(loc);
		return null;
	}
    
}
